class_name FileUtil
extends RefCounted


static func saveFile(data,name,ext = ".dat"):
	var path = "user://"+name+ext
	var file = FileAccess.open(path, FileAccess.WRITE)
	file.store_string(var_to_str(data))

static func loadFile(name,ext=".dat"):
	var path = "user://"+name+ext
	if FileAccess.file_exists(path):
		var file = FileAccess.open(path, FileAccess.READ)
		var text = file.get_as_text()
		return str_to_var(text)
	return null

static func loadAssets(path):
	if FileAccess.file_exists(path):
		var file = FileAccess.open(path, FileAccess.READ)
		var text = file.get_as_text()
		return str_to_var(text)
	return null
	
	
static func dir_contents(path) -> Dictionary:
	var dir = DirAccess.open(path)
	var dir_num = []
	var file_num = []
	if dir:
		dir.list_dir_begin()
		var file_name = dir.get_next()
		while file_name != "":
			if dir.current_is_dir():
				#print("发现目录：" + file_name)
				dir_num.append(file_name)
			else:
				#print("发现文件：" + file_name)
				file_num.append(file_name)
			file_name = dir.get_next()
	else:
		print("尝试访问路径时出错。")
	return {"dirs":dir_num,"file":file_num}
